package jp.gr.java_conf.yuzu_project;

import jp.gr.java_conf.yuzu_project.common.CommonUtil;
import jp.gr.java_conf.yuzu_project.common.SaveDataStock;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

/**
 * タイトル画面.
 * 
 * @author ゆずプロジェクト
 *
 */
public class TitleActivity extends Activity {
	
	/** スタートボタンクリックリスナー */
	private View.OnClickListener startButtonListener = 
			new OnClickListener() {
		
		public void onClick(View v) {
			SaveDataStock saveData = new SaveDataStock();
			Intent intent = new Intent(TitleActivity.this, PlayActivity.class);
			intent.putExtra(CommonUtil.SAVE_OBJ_INTENT_KEY, saveData);
			startActivityForResult(intent, CommonUtil.INTENT_CODE);
		}
	};
	
	/** ロードボタンリスナー */
	private View.OnClickListener loadButtonListener = 
			new OnClickListener() {
		
		public void onClick(View v) {
			Intent intent = new Intent(TitleActivity.this, SaveActivity.class);
			intent.putExtra(CommonUtil.SAVE_LOAD_INTENT_KEY, CommonUtil.LOAD_INTENT);
			startActivityForResult(intent, CommonUtil.INTENT_CODE);
		}
	};
	
	/** オプションボタンリスナー */
	private View.OnClickListener optionButtonListener = 
			new OnClickListener() {
		
		public void onClick(View v) {
			
		}
	};
	
	/** スペシャルボタンリスナー */
	private View.OnClickListener specialButtonListener = 
			new OnClickListener() {
		
		public void onClick(View v) {
			Intent intent = new Intent(TitleActivity.this, SpcialActivity.class);
			startActivityForResult(intent, CommonUtil.INTENT_CODE);
		}
	};

	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_title);
		
		//スタートボタン
		Button buttonStart = (Button) findViewById(R.id.title_start);
		buttonStart.setOnClickListener(startButtonListener);
		
		//ロードボタン
		Button buttonLoad = (Button) findViewById(R.id.title_load);
		buttonLoad.setOnClickListener(loadButtonListener);
		
		//オプションボタン
		Button buttonOption = (Button) findViewById(R.id.title_option);
		buttonOption.setOnClickListener(optionButtonListener);
		
		//スペシャルボタン
		Button buttonSpecial = (Button) findViewById(R.id.title_special);
		buttonSpecial.setOnClickListener(specialButtonListener);
		
	}

	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		
		if (requestCode == CommonUtil.INTENT_CODE && resultCode == Activity.RESULT_OK){
			Bundle extras = data.getExtras();
			if (extras != null){
				String text = extras.getString(CommonUtil.END_TEXT);
				if (CommonUtil.END_MESSAGE.equals(text)){
					finish();
				}
			}
		}
		
		super.onActivityResult(requestCode, resultCode, data);
	}

	
}
